class_name dingding2
extends JiGuan
@export var speed:float =200
@export var rot_delta:float = 0
@export var end_pos:Vector2=Vector2.ZERO
var begin_pos := Vector2.ZERO
var to_end:bool = true
var dir:Vector2
func _ready() -> void:
	begin_pos = self.global_position
	dir  = end_pos.normalized()



func _process(delta: float) -> void:
	rotation_degrees+=delta*rot_delta
	if to_end:
		global_position+=dir*speed*delta
		if abs((global_position-begin_pos).length()-end_pos.length())<5:
			to_end=false
	else:
		global_position-=dir*speed*delta
		if (global_position-begin_pos).length()<5:
			to_end = true
func attack_player(body):
	if body is Player:
		body.back((body.global_position-self.global_position).normalized())


func _on_body_entered(body: Node2D) -> void:
	attack_player(body)
